﻿using System;

interface IShape
{
    bool IsValid { get; }
    double Area { get; }
}

class Rectangle : IShape
{
    public double Width { get; set; }
    public double Height { get; set; }
    public Rectangle(double width, double height)
    {
        Width = width;
        Height = height;
    }
    public bool IsValid => Width > 0 && Height > 0;
    public double Area => IsValid ? Width * Height : 0;
}


class Square : Rectangle
{
    public Square(double side) : base(side, side) { }
}


class Triangle : IShape
{
    public double A { get; set; }
    public double B { get; set; }
    public double C { get; set; }

    public Triangle(double a, double b, double c)
    {
        A = a; B = b; C = c;
    }

    public bool IsValid => A + B > C && A + C > B && B + C > A;

    public double Area
    {
        get
        {
            if (!IsValid) return 0;
            double p = (A + B + C) / 2;
            return Math.Sqrt(p * (p - A) * (p - B) * (p - C));
        }
    }
}

class ShapeFactory
{
    static Random rnd = new Random();
    public static IShape CreateRandomShape()
    {
        switch (rnd.Next(3))
        {
            case 0: return new Rectangle(rnd.Next(1, 10), rnd.Next(1, 10));
            case 1: return new Square(rnd.Next(1, 10));
            default: return new Triangle(rnd.Next(1, 10), rnd.Next(1, 10), rnd.Next(1, 10));
        }
    }
}

class Program
{
    static void Main()
    {
        IShape[] shapes = new IShape[10];
        double totalArea = 0;
        for (int i = 0; i < shapes.Length; i++)
        {
            shapes[i] = ShapeFactory.CreateRandomShape();
            Console.WriteLine($"{shapes[i].GetType().Name}, 合法: {shapes[i].IsValid}, 面积: {shapes[i].Area:F2}");
            totalArea += shapes[i].Area;
        }
        Console.WriteLine($"总面积之和为: {totalArea:F2}");
    }
}
